package com.liveinstars.im.endpoint;

import com.liveinstars.im.core.service.RecommendFriendService;
import com.liveinstars.api.im.RecommendFriendApi;
import com.liveinstars.api.im.vo.RecommendFriendVO;
import com.onepiece.shipelves.common.Result;
import com.onepiece.shipelves.common.enums.SystemExceptionEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: zhouze
 * @date: 2020/3/6
 */
@RestController
public class RecommendFriendEndpoint implements RecommendFriendApi {

    @Autowired
    private RecommendFriendService recommendFriendService;

    @Override
    public Result add(@RequestParam("user_id") Long userId) {
        Result result = new Result<>();
        try {
            recommendFriendService.add(userId);
        } catch (Exception e) {
            result = SystemExceptionEnum.UN_KNOW_ERROR.createResult();
        }
        return result;
    }

    @Override
    public Result<List<RecommendFriendVO>> listAll() {
        Result<List<RecommendFriendVO>> result = new Result<>();
        try {
            List<RecommendFriendVO> list = recommendFriendService.listAll();
            result.setData(list);
        } catch (Exception e) {
            result = SystemExceptionEnum.UN_KNOW_ERROR.createResult();
        }
        return result;
    }

    @Override
    public Result updateSortById(@RequestParam("id")Long id, @RequestParam("sort")Integer sort) {
        Result result = new Result<>();
        try {
            recommendFriendService.updateSortById(id, sort);
        } catch (Exception e) {
            result = SystemExceptionEnum.UN_KNOW_ERROR.createResult();
        }
        return result;
    }

    @Override
    public Result deleteById(@RequestParam("id") Long id) {
        Result result = new Result<>();
        try {
            recommendFriendService.deleteById(id);
        } catch (Exception e) {
            result = SystemExceptionEnum.UN_KNOW_ERROR.createResult();
        }
        return result;
    }
}
